const data = require('../../db.js');
const router = require('express').Router();
const cName = 'spa';
const sName = 'spas';

router.get(`/${cName}`,(req,res)=>{
    // console.log(req.session)
// console.log(req.query.id);
 var c = req.query.id;
 console.log(c);
//  根据id查询数据
    data.query(`select * from course where id = ?`,c, (error, result) => {
        if(error){
            res.json({
                code:'400',
                message:'查询失败'
            })
        }else{
            res.json({
                code:'200',
                data:result
            })
        }
    })
})

router.get(`/${sName}`,(req,res)=>{
    var d = req.query.id;
    // 根据id查询数据
    data.query(`select * from chapter where cid = ?`,d,(error,result) => {
        if(error){
            res.json({
                code:'400',
                message:'查询失败'
            })
        }else{
            res.json({
                code:'200',
                data:result
            })
        }
    })
})
module.exports=router;
